package com.ruoyi.basedata.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.basedata.domain.OmsOrgunit;
import com.ruoyi.basedata.service.IOmsOrgunitService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 结算组织Controller
 * 
 * @author xiefeng
 * @date 2023-02-17
 */
@RestController
@RequestMapping("/settlementCenter/basedata/orgunit")
public class OmsOrgunitController extends BaseController
{
    @Autowired
    private IOmsOrgunitService omsOrgunitService;

    /**
     * 查询结算组织列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:orgunit:list')")
    @GetMapping("/list")
    public AjaxResult list(OmsOrgunit omsOrgunit)
    {
        List<OmsOrgunit> list = omsOrgunitService.selectOmsOrgunitList(omsOrgunit);
        return success(list);
    }

    /**
     * 导出结算组织列表
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:orgunit:export')")
    @Log(title = "结算组织", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OmsOrgunit omsOrgunit)
    {
        List<OmsOrgunit> list = omsOrgunitService.selectOmsOrgunitList(omsOrgunit);
        ExcelUtil<OmsOrgunit> util = new ExcelUtil<OmsOrgunit>(OmsOrgunit.class);
        util.exportExcel(response, list, "结算组织数据");
    }

    /**
     * 获取结算组织详细信息
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:orgunit:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(omsOrgunitService.selectOmsOrgunitById(id));
    }

    /**
     * 新增结算组织
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:orgunit:add')")
    @Log(title = "结算组织", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OmsOrgunit omsOrgunit)
    {
        int i = omsOrgunitService.insertOmsOrgunit(omsOrgunit);
        if (i == -1){
            return error("没有找到父级编码对应的组织");
        }
        return toAjax(i);
    }

    /**
     * 修改结算组织
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:orgunit:edit')")
    @Log(title = "结算组织", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OmsOrgunit omsOrgunit)
    {
        return toAjax(omsOrgunitService.updateOmsOrgunit(omsOrgunit));
    }

    /**
     * 删除结算组织
     */
    @PreAuthorize("@ss.hasPermi('settlementCenter/basedata:orgunit:remove')")
    @Log(title = "结算组织", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(omsOrgunitService.deleteOmsOrgunitByIds(ids));
    }
}
